
/** 标签表 */
const classMap = new Map<Configuration, ClassBase>();
/** 机关基类 */
export default class ClassBase implements clazz.ClassBase {
    private tags: {
        [key: string]: boolean
    } = {}
    /** 关联的实体 */
    instance?: Instance

    /** 设置标签 */
    protected setTag(tag: keyof clazz.Instances) {
        const clazz = classMap.get(this.config);
        if (clazz) {
            clazz.tags[tag] = true;
        }
    }
    /**
     * 根据Configuration 获取clazz实例
     * @param config 
     * @param tag 
     * @returns 
     */
    static getA<T extends keyof clazz.Instances>(config: Configuration, tag: T) {

        const clazzInstance = classMap.get(config);
        if (!clazzInstance) return
        if (clazzInstance.tags[tag]) {
            return classMap.get(config) as unknown as clazz.Instances[T]
        }
    }

    /** 类型名称 */
    clazz: keyof clazz.Instances
    constructor(public config: Configuration) {
        this.instance = config.Parent
        this.clazz = config.Name as keyof clazz.Instances;
        classMap.set(config, this)
        this.setTag('ClassBase');

    }
    IsA<T extends keyof clazz.Instances>(className: T): this is clazz.Instances[T] {
        if (this.clazz === className) {
            return true
        }
        return false
    }

}